﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListSelect.aspx.cs" Inherits="Bingosoft.WebApp.Modules.SecurityConsole.Common.FunctionControl.ListSelect.ListSelect" %>
<%@ Import Namespace="Bingosoft.Modules.SecurityConsole.Common.Helper" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 <web:Script ID="Script1" src="~/Scripts/jquery.js" runat="server" />
    <web:Script ID="Script2" src="~/Scripts/jquery.utils.js" runat="server" />
    <web:Script ID="Script3" src="~/Scripts/jquery_plugins/jquery.json.js" runat="server" />
<script type="text/javascript">
    var Global = {};
    Global.contextPath = '<%= RequestHelper.GetContextPath(Request) %>';
    var paramsString = "<%=Request.Params["params"]%>";
    var params = eval("(" + paramsString + ")");

 	$(function () {
        <%if(!string.IsNullOrEmpty(Request.Params["groupDataSourceType"]))
        {%>
 	    initCatalogDropDownList();
        <%
        }%>
        <%if(!string.IsNullOrEmpty(Request.Params["selectedListDataSourceType"]))
        {%>
 	    initSelectedDropDownList();
        <%
        }%>
        searchProperty();
 	});

	   
       //初始化选择下拉列表
	    function initCatalogDropDownList() {
            var catalogListString = "<%=groupListString %>";
            var catalogList = eval("(" + catalogListString + ")");
            var option = new Option("全部", "");
	        document.getElementById('groupId').options.add(option);
            for (var i = 0; i < catalogList.length; i++) {
	            var one = catalogList[i];
	            option = new Option(one['text'], one['id']);
	            if ('<%=Request.Params["defaultOption"] %>' != '' && '<%=Request.Params["defaultOption"] %>' == one['id']) 
                {
	                option.selected = true;
	            }

	            document.getElementById('groupId').options.add(option);
	        }
	        if ('<%=Request.Params["defaultOption"] %>' == '' && document.getElementById('groupId').options.length > 0) 
            {
	            document.getElementById('groupId').options[0].selected = true;
	        }
        }

         //初始化已选列表内容
	    function initSelectedDropDownList() {
            var selectedListString = "<%=selectedListString %>";
            var selectedList = eval("(" + selectedListString + ")");

             for (var i = 0; i < selectedList.length; i++) {
	            var one = selectedList[i];
	            var option = new Option(one['text'], one['id']);

	            document.getElementById('result').options.add(option);
	        }
        }

	    /**
	    响影查询按钮的事件
	    */
	    function searchProperty() {
	        var va = {};
	        var vv = document.getElementById('propertyName');
	        if (vv != null) {
	            va.name = vv.value;
	        }
            <%if (!string.IsNullOrEmpty(Request.Params["groupLabel"]))
              {%>
	            var selectEle = document.getElementById('groupId');
	            if (selectEle != null) {
	                va.groupId = selectEle.value;
	            }
            <%
              }%>

	        var _params = $.extend(params, va );
	        $.dataservice("sqlid:<%=Request.Params["selectListDataSource"] %>", _params, refreshHandler, { async: false });
	    }

	  
	    function refreshHandler(r) {
	        document.getElementById("properties").length = 0;
	        for (var i = 0; i < r.length; i++) {
	            var option = new Option(r[i][1], r[i][0]);
	            document.getElementById("properties").options.add(option);
	        }
	    }
	    
	    /**返回select里选中的项，属性导入框架通用*/
	    function onOK(id) {
	        var source = document.getElementById(id);
	        var ops = source.options;
	        if (ops.length < 1) {
	            alert("对不起，您没有选择数据");
	            return;
	        }

	        returnImportValues(id);
	    }
	    //将用户选择的结果直接保存到数据库
	    function onSave(id) {
	        //LoadingBar.lock();
	        var source = document.getElementById(id);
	        var ops = source.options;
	        var ids = "";
	        var names = "";
	        if (ops.length < 1) {
	            alert("对不起，您没有选择数据");
	            //LoadingBar.unlock();
	            return;
	        }
	        for (var i = 0; i < ops.length; i++) {
	            ids = ids + "," + ops[i].value;
	            names = names + "," + ops[i].innerText;
	        }

	        var _params = $.extend(params, {oldIds:"", oldNames:"",newIds:ids,newNames:names});
	        $.dataservice("<%=Request.Params["saveService"]%>$Save", _params, saveResult, { async: false });
	    }

	    function saveResult(r) {
	        if (r == true) {
	            alert("保存成功!");
	            window.returnValue = r;
	            window.close();
	        } else {
	            alert("保存失败了!");
	        }
	    }

	    /**
	    *下拉选择改变时操作
	    */
	    function selectChange() {
	        var groupId = document.getElementById('groupId').value;
	        var _params = $.extend(params, { groupId: groupId });
            $.dataservice("sqlid:<%=Request.Params["selectListDataSource"] %>", _params, refreshHandler, { async: false });
	    }

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>左右选择功能控件</title>
     <link type="text/css" rel="stylesheet" href="listSelect.css" />
   
    <web:Script ID="Script5" src="~/Modules/SecurityConsole/Common/FunctionControl/ListSelect/select_tool.js" runat="server" />
</head>

 
<body id="master">
	 <table width="100%" height="400px" border="0" cellpadding="0" cellspacing="0" id="Table1">
        <tr>
            <td>
                <table width="100%" border="0" cellpadding="0" cellspacing="0" id="Table2" height="20px;">
                    <tr>
                        <td class="frame1_bd_01">
                        </td>
                        <td class="frame1_bd_02">
                            <table width="*" cellpadding="0" cellspacing="0" class="ow_hdr_mg" id="Table5">
                                <tr>
                                    <td class="ow_hdr_i">
                                        <img src="Images/ow_hdr_i.gif" border="0">
                                    </td>
                                    <td class="ow_hdr_f">
                                       <%=Request.Params["title"] %>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td class="frame1_bd_03">
                            <img src="Images/space.gif">
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr >
            <td height="100%" align="center" valign="top" style="padding-top: 10px;">
                <!-- 页面主体 -->
                <div  style="height: 100%;">
                    <table width="100%" cellpadding="0" cellspacing="0" class="layout_lr" border="0">
                        <tr>
                                <td class="right" >
                                    <!-- 列表框 -->
                                    <% if (!(string.IsNullOrEmpty(Request.Params["searchLabel"]) && string.IsNullOrEmpty(Request.Params["groupLabel"])))
                                       { %>
                                    <div class="search" >
                                        <!-- 查询信息 -->
                                        <form id="queryForm" name="queryForm" action="" onsubmit="return false;">
                                        <table cellpadding="0" cellspacing="0" width="96%">
                                            <tr>
                                           <%if (!string.IsNullOrEmpty(Request.Params["groupLabel"]))
                                             {%>
                                                <td>
                                                         <%=Request.Params["groupLabel"]%>
                                                </td>
                                                <td>
	                                                <select name="groupId" id="groupId" onchange="selectChange()" style="width:120px;">
	                                                </select>
                                                </td>
                                          <%} %>  
									       <%if (!string.IsNullOrEmpty(Request.Params["searchLabel"]))
                                                 {%>
                                                <td>
                                                          <%=Request.Params["searchLabel"]%>
                                                </td>
								             	<td>
									             	<input type="text" size="15" maxlength="90" onkeydown="javascript:void(0);" id="propertyName"/>
									            </td>
									             <td class="button">
                                                    <a href="javascript:" onclick="searchProperty()">
                                                       <span>
                                                         <img src="Images/ico_search.gif">查询
                                                       </span>
                                                    </a>
                                                    <a href="javascript:" onclick="document.forms['queryForm'].reset();">
                                                       <span>
                                                         <img src="Images/ico_reset.gif">重置
                                                       </span>
                                                    </a>
                                                </td> 
									       <%} %>    							 
                                            </tr>
                                        </table>
                                        </form>	
                                    </div><!-- search结束 -->
                                   <%} %>
                                    <div class="bottomform" style="height:345px;">
                                        
                                        <table width="100%" cellpadding="0" cellspacing="0" class="selectuserform" border="0" style="position:relative;top:-3px;">
                                            <tr height="23px;" style="background-color:#F1F6FF;">
                                                <td width="2%">&nbsp;</td>
                                                <td width="40%" align="center" style="background-color:#F1F6FF;font-size: 13px;">
                                                       可 选 项
                                                </td>
                                                <td width="20%">&nbsp;
                                                    
                                                </td>
                                                <td width="40%" align="center" style="background-color:#F1F6FF;">
                                                         已 选 项
                                                </td>
                                                <td width="2%">&nbsp;</td>
                                            </tr>
                                            <tr>
                                                <td width="2%">&nbsp;</td>
                                                <td >
                                                    
								                    <select id="properties" name="properties" multiple="multiple" style="width: 230px; height: 310px;border: solid 1px #a8cfeb;" ondblclick="cutTo('properties','results','<%=Request.Params["multiple"]%>')">								               			
								               		</select>
                                                </td>
                                                <td align="center">
                                                    <table cellpadding="10px" cellspacing="0" border="0">
                                                   
                                                   <% if("true".Equals(Request.Params["multiple"])){ %>
                                                   <tr><td align="center">
		                                                    <a href="javascript:void(0);" class="combtn" onclick="cutAllTo('properties','results','<%=Request.Params["multiple"]%>')">
		                                                       <span style="width:30px">
		                                                         &gt;&gt;
		                                                       </span>
		                                                    </a>
                                                    </td></tr>
													<%} %>		
                                                     <tr><td align="center">	
		                                                    <a href="javascript:void(0);" class="combtn" onclick="cutTo('properties','results','<%=Request.Params["multiple"]%>')">
		                                                       <span style="width:30px">
		                                                         &nbsp;&gt;
		                                                       </span>
		                                                    </a>
                                                    </td></tr>
                                                     <tr><td align="center">
		                                                    <a href="javascript:void(0);" class="combtn" onclick="cutTo('results','properties','true')">
		                                                       <span style="width:30px">
		                                                         &nbsp;&lt;
		                                                       </span>
		                                                    </a>
                                                        </td></tr>
                                                        <tr><td align="center">
		                                                    <a href="javascript:void(0);" class="combtn" onclick="cutAllTo('results','properties','true')">
		                                                       <span style="width:30px">
		                                                         &lt;&lt;
		                                                       </span>
		                                                    </a>
                                                        </td></tr>
														 </table>
                                                </td>
                                                <td >
								                    <select id="results" name="results" multiple="multiple" style="width: 230px; height: 310px;border: solid 1px #a8cfeb;" ondblclick="cutTo('results','properties','true')">
								               		</select>
                                                </td>
                                                
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                        </tr>
                    </table>
                </div><!-- class="content" div结束 -->
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%" border="0" cellpadding="0" cellspacing="0"  height="20px;">
                    <tr>
                        <td class="frame1_bd_07">
                        </td>
                        <td class="frame1_bd_08">
                            <table cellpadding="0" cellspacing="0" class="ow_btm_mg" id="Table6">
                                <tr>
                                    <td class="ow_btm_msg">
                                    </td>
                                    <td class="ow_btm_btn">
                                        <!------------------ 按钮 ------------------>
                                         <% if (!string.IsNullOrEmpty(Request.Params["saveService"]))
                                            {
                                         %>
                                         <a href="javascript:" class="combtn" onclick="onSave('results')"><span ><img src="Images/ico_save.gif">保存</span></a>
                                         <%
                                             }
                                            else
                                            {
%>
                                        <a href="javascript:" class="combtn" onclick="onOK('results')"><span><img src="Images/true.gif">确定</span></a> 
                                        <%
                                            }%>
                                        <a href="javascript:window.close();"
                                            class="combtn" ><span><img  src="Images/ico_009a.gif"/>关闭</span></a>
                                        <!------------------END 按钮 --------------->
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td class="frame1_bd_09">
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
  </body>
</html>
